package cn.zfgc.zface.entity;

import cn.zfgc.base.api.DateTimeUtils;
import cn.zfgc.base.api.JsonUtils;
import cn.zfgc.base.api.time.constant.DateTimeFormat;
import cn.zfgc.jfinal.plugin.activerecord.Model;
import cn.zfgc.zface.constant.CommonConstant;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.Map;

/**
 * @author caoyuan
 */
@Getter
@Setter
public class CompanyEntity extends Model<CompanyEntity> {
    public final static CompanyEntity DAO = new CompanyEntity().dao();

    private String ID;

    private String companyName;

    private String createTime;

    private String updateTime;

    private String state;

    private String createUserName;

    public static CompanyEntity paraToCompany(Map<String, String[]> paramMaps){
        CompanyEntity companyEntity = new CompanyEntity();
        companyEntity.setCompanyName(paramMaps.get("companyName")[0]);
        companyEntity.setCreateUserName(paramMaps.get("createUserName")[0]);
        companyEntity.setCreateTime(DateTimeUtils.date2String(new Date(), DateTimeFormat.Format2.toString()));
        companyEntity.setUpdateTime(DateTimeUtils.date2String(new Date(), DateTimeFormat.Format2.toString()));
        companyEntity.setState(CommonConstant.NOT_DELETE);
        return companyEntity;
    }

    @Override
    public <T extends Model> T fieldsToAtts(T t) {
        Map attrs = super.getAttrs();
        attrs.put("companyName", this.getCompanyName());
        attrs.put("createTime", this.getCreateTime());
        attrs.put("updateTime", this.getUpdateTime());
        attrs.put("state", this.getState());
        attrs.put("createUserName", this.getCreateUserName());
        return t;
    }

    @Override
    public String toString() {
        return "CompanyEntity{" + JsonUtils.toJson(this) + '}';
    }
}
